package com.example.g7640.util;

import com.example.g7640.dto.SessionDto;
import org.springframework.core.NamedThreadLocal;

public class SessionLocal {

    public static final String SESSION = "_session";

    private static ThreadLocal<SessionDto> threadLocal = new NamedThreadLocal<>(SESSION);


    public static SessionDto getSession(){
        return threadLocal.get();
    }

    public static String getAccount(){
        SessionDto session = getSession();
        if(session == null){
            return null;
        }
        return session.getAccount();
    }


    public static void setSession(SessionDto session){
        threadLocal.set(session);
    }


    public static Integer getLoginId(){
        SessionDto session = getSession();
        if(session == null){
            return null;
        }
        return session.getId();
    }
}
